################################################################################
#
#Copyright (c) 2011, Petr Skramovsky
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#    * Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in the
#      documentation and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL Petr Skramovsky BE LIABLE FOR ANY
#DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################

MD3_MAGIC = 0x33504449
MD3_VERSION = 15
MAX_QPATH = 64
MD3_MAX_FRAMES = 1024
MD3_MAX_TAGS = 16
MD3_MAX_SURFACES = 32
MD3_MAX_SHADERS = 256
MD3_MAX_VERTS = 4096
MD3_MAX_TRIANGLES = 8192
MD3_XYZ_SCALE = 1.0 / 64.0

class Vector:
  def __init__(self):
    self.x = 0
    self.y = 0
    self.z = 0
  
class Vertex:
  def __init__(self):
    self.x = 0
    self.y = 0
    self.z = 0
    self.nx = 0
    self.ny = 0
    self.nz = 0

class Triangle:
  def __init__(self):
    self.a = 0
    self.b = 0
    self.c = 0

class ST:
  def __init__(self):
    self.s = 0
    self.t = 0

class Tag:
  def __init__(self):
    self.name = ""
    self.origin = Vector()
    self.axis = [ None ] * 3

class Frame:
  def __init__(self):
    self.min_bounds = Vector()
    self.max_bounds = Vector()
    self.local_origin = Vector()
    self.radius = 0
    self.name = ""

class Shader:
  def __init__(self):
    self.name = ""
    self.index = 0
  
class Surface:
  def __init__(self):
    self.ident = 0
    self.name = ""
    self.flags = 0
    self.num_frames = 0
    self.num_shaders = 0
    self.num_verts = 0
    self.num_triangles = 0
    self.ofs_triangles = 0
    self.ofs_shaders = 0
    self.ofs_st = 0
    self.ofs_xyznormal = 0
    self.ofs_end = 0
    self.shaders = []
    self.triangles = []
    self.st = []
    self.vertexes = []

class MD3:
  def __init__(self):
    self.ident = 0
    self.version = 0
    self.name = ""
    self.flags = 0
    self.num_frames = 0
    self.num_tags = 0
    self.num_surfaces = 0
    self.num_skins = 0
    self.ofs_frames = 0
    self.ofs_tags = 0
    self.ofs_surfaces = 0
    self.ofs_eof = 0
    self.frames = []
    self.tags = []
    self.surfaces = []
    